package admin

import (
	"editor/constant"
	"editor/service/mdFile"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ListHandler(c *gin.Context) {
	newList, err := mdFile.GetListItemWithDir4Admin(c)
	if err != nil {
		c.Writer.WriteHeader(http.StatusOK)
		_, _ = c.Writer.Write([]byte("get file list failed, error:" + err.Error()))
		return
	}

	//fmt.Println("----------------------------")
	//bt, _ := json.MarshalIndent(map[string]interface{}{
	//	"newList": newList,
	//	"err":     err,
	//}, "", "  ")
	//fmt.Println(string(bt))
	//fmt.Println("----------------------------")

	c.HTML(http.StatusOK, "admin.html", gin.H{
		"Title":    constant.Config.App.Name,
		"FileList": newList,
		"User":     c.GetString(constant.UserName),
	})
}
